<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('修改上级店铺')"/>
</head>
<body>
<div class="main-content">
    <form id="form-shop-parent-change" class="form-horizontal" th:object="${shopInfo}">
        <input id="shopId" name="shopId" type="hidden" th:value="*{id}">
        <input id="parentId" name="parentId" type="hidden" th:field="*{parentId}"/>
        <input id="isCheck" type="hidden" value="0">
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label "><span style="color: red; ">*</span>上级店铺：</label>
                    <div class="col-sm-6">
                        <div class="input-group">
                            <input class="form-control" type="text" id="treeName" onclick="selectShopTree()"
                                   readonly="true"
                                   th:field="*{parentShopName}">
                            <span class="input-group-addon"><i class="fa fa-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">站点名称：</label>
                    <div class="col-sm-6">
                        <input id="shopName" class="form-control" type="text" th:value="*{shopName}" disabled>
                    </div>
                </div>
            </div>
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label"><span style="color: red; ">*</span>财务密码：</label>
                    <div class="col-sm-6">
                        <input id="password" class="form-control" name="password" type="password" required/>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "back/shop";

    function selectShopTree() {
        var parentId = $("#parentId").val();
        var options = {
            title: '上级店铺选择',
            width: "380",
            url: prefix + "/selectShopTree/" + parentId,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function submitHandler() {
        let parentId = $("#parentId").val();
        let shopId = $("#shopId").val();
        if (parentId == shopId) {
            $.modal.alertError("上级店铺不能选择自己！")
            return false;
        }
        let password = $('input[name="password"]').val();
        if ($.common.isEmpty(password)) {
            $.modal.alertError("请输入财务密码！")
            return false;
        }
        if ($.validate.form()) {
            $.operate.save(prefix + "/changeParent", $('#form-shop-parent-change').serializeArray());
        }
    }

    function doSubmit(index, layero) {
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        var body = layer.getChildFrame('body', index);
        $("#parentId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        layer.close(index);
    }
</script>
</body>
</html>